package com.moguo.guoaiagent.demo.invoke;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.messages.AssistantMessage;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * @program: guo-ai-agent
 * @description: 用spring Ai调用Ai大模型
 * @author: moguo
 * @create: 2025-04-27 17:01
 **/
//直接启动GuoAiAgentApplication.java启动项目进行测试
@Component
public class SpringAIIncoke implements CommandLineRunner {
    @Resource
    private ChatModel dashscopeChatModel;

    @Override
    public void run(String... args) throws Exception {
        AssistantMessage assistantMessage = dashscopeChatModel.call(new Prompt("你好，我是小郭郭"))
                .getResult()
                .getOutput();
        System.out.println(assistantMessage.getText());
    }
}

